package linkedlist.test328;

import listbyorder.utils.ListNode;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/7/15 12:38
 */
public class Solution1 {
    public ListNode oddEvenList(ListNode head) {
        if (head == null || head.next == null) return head;
        ListNode odd = head;
        ListNode even = head.next;
        ListNode o = odd, e = even;
        ListNode t = head.next.next;
        int index = 1;
        while (t != null) {
            if ((index & 1) == 1) {
                o.next = t;
                o = o.next;
            } else {
                e.next = t;
                e = e.next;
            }
            t = t.next;
            index++;
        }
        e.next = null;
        o.next = null;
        o.next = even;
        return odd;
    }
}
